package com.example.community.del;

import com.example.community.dao.FloorDao;
import com.example.community.dao.UnitDao;
import com.example.community.model.Unit;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/floorDeleteServlet")
public class FloorDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String fno = req.getParameter("fno");
        UnitDao unitDao = new UnitDao();
        List<Unit> units = unitDao.selectfNo(Integer.parseInt(fno));
        if (units.size() == 0){
            FloorDao floorDao = new FloorDao();
            Integer delete = floorDao.delete(Integer.parseInt(fno));
            if (delete == 1){
                // 删除成功
                resp.getWriter().write("true");
//                System.out.println("删除成功");
            }else {
                // 删除失败
                resp.getWriter().write("false");
//                System.out.println("删除失败");
            }
        }else {
            resp.getWriter().write("false");
        }
    }
}
